package demo4;

import java.util.Comparator;

/**
 * @Author: XXHH
 * @CreateTime: 2025-01-12
 */
public class Student implements Comparator<Student> {
    public String name;
    public int age;

    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
    //    @Override
//    public int compareTo(Student o) {
//        // 比较年龄
//        //return  this.age - o.age;
//        return this.name.compareTo(o.name);
//    }

    @Override
    public int compare(Student o1, Student o2) {
        return o1.age - o2.age;
    }
}
